package com.friends.digitpic.controller;

import com.friends.common.tools.util.HttpMessage;
import com.friends.digitpic.business.service.PicBusinessService;
import com.friends.digitpic.service.entity.PicEntity;
import com.friends.digitpic.service.service.PicService;
import org.jeecgframework.minidao.pojo.MiniDaoPage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by fusio on 2018/9/15.
 */
@Controller
@RequestMapping("/picture")
public class PictureController {

    @Resource
    private PicService picService;

    @Resource
    private PicBusinessService picBusinessService;
    /**
     * 根据id查询图片信息
     * @param picid
     * @return
     */
    @RequestMapping("/GetPictureInfo.html")
    @ResponseBody
    public HttpMessage GetPictureInfo(
            @RequestParam(value = "picid", required = true)
            String picid){
        PicEntity entity = picService.getPic(picid);
        if(entity!=null)
            return HttpMessage.createSuccessMsg(entity);
        return HttpMessage.createErrorMsg("未找到图片信息");
    }

    /**
     * 根据groupid查询下属图片信息
     * @param groupid
     * @param page
     * @param row
     * @return
     */
    @RequestMapping("/GetPicturesByGroup.html")
    @ResponseBody
    public HttpMessage GetPicturesByGroup(
            @RequestParam(value = "groupid", required = true)
            String groupid,
            @RequestParam(value = "page", required = true)
            int page,
            @RequestParam(value = "row", required = true)
            int row){
        MiniDaoPage<PicEntity> entities = picBusinessService.getPicturesByGroup(groupid,page,row);
        return  HttpMessage.createSuccessMsg(entities);
    }

    /**
     * 根据类型查询下属图片信息
     * @param kindName
     * @param page
     * @param row
     * @return
     */
    @RequestMapping("/GetPictruesByKind.html")
    @ResponseBody
    public HttpMessage GetPictruesByKind(
            @RequestParam(value = "groupid", required = true)
            String kindName,
            @RequestParam(value = "page", required = true)
            int page,
            @RequestParam(value = "row", required = true)
            int row
    ){
        MiniDaoPage<PicEntity> entities = picBusinessService.getPictruesByKind(kindName,page,row);
        return  HttpMessage.createSuccessMsg(entities);
    }

    /**
     * 根据位置查询图片信息
     * @param location
     * @param page
     * @param row
     * @return
     */
    @RequestMapping("/GetPictrueByLocation.html")
    @ResponseBody
    public HttpMessage GetPictrueByLocation(
            @RequestParam(value = "location", required = true)
            String location,
            @RequestParam(value = "page", required = true)
            int page,
            @RequestParam(value = "row", required = true)
            int row
    ){
        PicEntity entity = new PicEntity();
        entity.setLocation(location);
        MiniDaoPage<PicEntity> entities = picService.getPicAll(entity,page,row);
        return HttpMessage.createSuccessMsg(entities);
    }



}
